package test4;

import java.util.Scanner;

public class Capnumber {
    public static void main(String[] args) {
        //键盘录入
        Scanner sc = new Scanner(System.in);
        int money;


        while(true) {
            System.out.println("请输入一个金额");
            money = sc.nextInt();
            //判断数字是否符合要求
            if (money >= 0 && money <= 9999999) {
                break;
            } else {
                System.out.println("金额无效");
                continue;
            }
        }
        String moneystr= " ";
        while(true) {
            //循环得到money中的每一位数字
            int ge = money % 10;
            //调用方法变成大写
            String capnumber = getCapnum(ge);
            //将大写数字拼接起来，顺序从左到右
            moneystr = capnumber+moneystr;
            money = money / 10;
            if(money == 0){
                break;
            }

        }
        //前边补0，变成七位
        int count = 8-moneystr.length();
        for (int i = 0; i < count; i++) {
            moneystr = "零"+moneystr;
        }

        //插入单位
        String[] arr= {"佰","拾","万","仟","佰","拾","元"};
        //遍历moneystr,把单位插进去
        //先输出数字，再输单位
         for(int i=0;i<moneystr.length();i++){
             System.out.print(moneystr.charAt(i));
             System.out.print(arr[i]);
         }
    }

    //定义方法把数字当成索引对应其大写
    public static String getCapnum (int number){
        //先把大写数字定义数组
        String[] arr = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
        return arr[number];
    }
}
